package com.webserver.controller;

import com.webserver.core.annotations.Controller;
import com.webserver.core.annotations.RequestMapping;
import com.webserver.http.HttpRequest;
import com.webserver.http.HttpResponse;
import qrcode.QRCodeUtil;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

@Controller

/**
 * 工具相关
 */
public class ToolsController {
    /**
     * 生成二维码
     *
     * @param request
     * @param response
     */
    @RequestMapping("/myweb/createQR")
    public void createQR(HttpRequest request, HttpResponse response) {
        System.out.println("开始生成二维码");
        String content = request.getParameters("content");
        System.out.println(content);
        try {
            QRCodeUtil.encode(content, response.getOutputStream());
            response.setContentType("image/jpeg");
            System.out.println("生成完毕!");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("二维码生成完毕");
    }

//    public static void main(String[] args) {
//        //        String str = "SuperIdol的笑容都没你的甜";
//        String str = "http://doc.canglaoshi.org";
//        try {
//            FileOutputStream fos = new FileOutputStream("qr.jpg");
////            QRCodeUtil.encode(str,fos);
//            QRCodeUtil.encode(str, "./logo.jpg", fos, true);
//            System.out.println("生成完毕!");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
}
